package com.ztools.wx.service.impl;

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ztools.api.service.pc.PcMemberService;
import com.ztools.common.model.pc.information.InformationPoint;
import com.ztools.common.model.pc.information.InformationSignIn;
import com.ztools.common.model.pc.information.WeChatMember;
import com.ztools.common.util.common.PageUtil;
import com.ztools.wx.service.WxMemberService;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.ztools.common.util.wx.RedisUtil.CACHE_WX_USER_PREFIX;

/**
 * @Author:seeTools
 * @Date: 2023/4/15  15:15
 * @Version 1.0
 */
@Service
public class WxMemberServiceImpl implements WxMemberService {

    @Reference(version = "1.0", check = false, timeout = 3000)
    public PcMemberService pcMemberService;
    @Resource
    public StringRedisTemplate stringRedisTemplate;

    @Override
    public WxMpUser getUserInfo(String openid) {
        WxMpUser wxMpUser;
        String memberStr = stringRedisTemplate.opsForValue().get(CACHE_WX_USER_PREFIX + openid);
        if (StrUtil.isNotEmpty(memberStr)) {
            wxMpUser = JSONUtil.toBean(memberStr, WxMpUser.class);
            return wxMpUser;
        }
        return null;
    }

    @Override
    public WeChatMember getMemberInfo(String openid) {
        return pcMemberService.getMemberInfo(openid);
    }

    @Override
    public boolean checkSing(Long memberId) {
        return pcMemberService.checkSing(memberId);
    }

    @Override
    public boolean signIn(InformationSignIn informationSignIn) {
        return pcMemberService.signIn(informationSignIn);
    }

    @Override
    public Page<InformationPoint> getPointRecord(PageUtil<InformationPoint> pageUtil) {
        return pcMemberService.getPointRecord(pageUtil);
    }
}
